package cn.zorbus.laian.infrastructure.config;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;
import org.apache.commons.lang3.StringUtils;

import java.io.IOException;

/**
 * create in 2023/12/29 13:26
 *
 * @author shishaodong
 * @version 0.0.1
 */
public class FilenameSerializer extends JsonSerializer<String> {

    @Override
    public void serialize(String s, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException {
        if (StringUtils.length(s) >= 15) {
            String res = StringUtils.substring(s, 0, 6);
            jsonGenerator.writeObject(res + "...");
        }
    }
}
